package cn.jly.flink.operators;

import cn.jly.flink.entity.Employee;
import cn.jly.flink.utils.ConstantUtils;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.java.ExecutionEnvironment;

import java.math.BigDecimal;

/**
 * @PackageName cn.jly.flink.operators
 * @ClassName FilterDemo
 * @Description 测试filter算子
 * @Author 姬岚洋
 * @Date 2021/1/8 下午 4:46
 */
public class FilterDemo {
    public static void main(String[] args) throws Exception {
        final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

        env.fromElements(
                new Employee(ConstantUtils.ID_GENERATOR.getAndIncrement(), "tom", BigDecimal.valueOf(10000)),
                new Employee(ConstantUtils.ID_GENERATOR.getAndIncrement(), "lily", BigDecimal.valueOf(20000)),
                new Employee(ConstantUtils.ID_GENERATOR.getAndIncrement(), "james", BigDecimal.valueOf(30000))
        )
                .filter(new FilterFunction<Employee>() {
                    @Override
                    public boolean filter(Employee employee) throws Exception {
                        // name length greater than 4
                        return employee.getName().length() > 4;
                    }
                })
                .print();
    }
}
